/**
 * @author ahammer
 * @date   2009
 * @update 
 */

/*
 * This file is part of Iqm.
 * Copyright (c) 2010-2011 Helmut Ahammer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package main;

import java.awt.Color;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ManagerListCellRenderer extends JLabel implements ListCellRenderer {

	public ManagerListCellRenderer() {
		this.setOpaque( true );
		this.setVerticalTextPosition(JLabel.BOTTOM);
		this.setHorizontalTextPosition(JLabel.CENTER);
		//this.setSize(new Dimension(100, 120));
		//this.setPreferredSize(new Dimension (100,120));
	}
	//value is here a single ImageIcon
	public Component getListCellRendererComponent(JList list, Object value,
			                                      int index,
			                                      boolean isSelected,
			                                      boolean cellHasFocus) {
	    //System.out.println("I'm here in the ManagerListCellRenderer");
		//if (value != null){
			//int maxIcons = 50;
			//ImageIcon ManagerIcon = (ImageIcon) value;
			//int numStack = ((DefaultListModel) value).getSize();
			//ImageIcon TankIcon = IqmTools.createTankThumb(img);
			//int PixSz = img.getColorModel().getPixelSize();
            //int NumBd = img.getNumBands();
            
            //String Typ = "Unknown Image Type";
		    //if ((PixSz == 24) && (NumBd == 3)) {Typ = "RGB";}
		    //if ((PixSz ==  8) && (NumBd == 1)) {Typ = "8-bit";}
		    //if ((PixSz == 16) && (NumBd == 1)) {Typ = "16-bit";}
		    //System.out.println("value is instance of: "+ value.getClass().toString());

			
			//System.out.println("ManageListCellRenderer: numStack  " + numStack);
			//maximal Anzahl von  icons werden gezeigt, Rest nur mit Bild Nummer
			//geht nicht, da alle Zellen immer gleich formatiert sind
//			int numStack = 0;
//			if (ManagerFrame.jRadioButtonMain.isSelected()) {
//				numStack = ManagerFrame.managerList.getModel().getSize();
//				//numStack = ManagerFrame.managerModel.getSize();
//		    }
//			if (ManagerFrame.jRadioButtonMain2.isSelected()) {
//				numStack = ManagerFrame.managerList2.getModel().getSize();
//				//numStack = ManagerFrame.managerModel2.getSize();
//			}
			
//			int[] vec = new int[maxIcons]; //Anzahl der maximal angezeigten Icons;
//			for (int i = 0; i < maxIcons; i++){
//				vec[i] = Math.round((float)i*numStack/maxIcons);
//				System.out.println("ManageListCellRenderer: i vec[i]   " + i + " "+vec[i] );
//			}
//			for (int i = 0; i < maxIcons; i++){
//				if (index == vec[i])  {
//					this.setIcon((ImageIcon)value);
//					System.out.println("ManageListCellRenderer: i  index vec[i]   " + i +"  "+ index + " "+vec[i] );
//					
//				}
//			}
			//wenn mehr Bilder als maxIcons vorhanden, werden nur die Bildnummer dargestellt
		//if (numStack > maxIcons){
			if (value == null){//ob Icon null oder nicht nul ist wird in Tank.setManager bestimmt
				this.setIcon(null);
				//this.setMaximumSize(new Dimension(20,20));
				//this.setSize(20, 20);
				//this.setPreferredSize(new Dimension(30,100));
			}
			else{
				//this.setPreferredSize(new Dimension(80,100));
				this.setIcon((ImageIcon)value);
			}
			//this.setFont(new Font("Arial", Font.PLAIN, 11));
			this.setText(" "+(index+1)+" ");
			
			//if (numStack == 1) this.setText(""+(index+1)+                  "         "+Typ);
			//if (numStack >  1) this.setText(""+(index+1)+" ("+numStack+")"+"         "+Typ);
			if ( !isSelected ) {
				this.setBackground( Color.white );
				this.setForeground( Color.black );
			}
			else {
				this.setBackground( list.getSelectionBackground() );
				this.setForeground( list.getSelectionForeground() );
			}
			
			//return null;			
		//}
		return this;
	
	}

}
